﻿import flash.geom.Point;
import flash.geom.Matrix;
class com.embedchat.skins.standart.button.SubmitButtonClass extends MovieClip{
	static var instanceName:String = new String ("SubmitButtonClass");
	static var instanceOwner:Object = com.embedchat.skins.standart.button.SubmitButtonClass;
	[Inspectable(name="Button label", defaultValue="Submit",type:String)]
	public var buttonLabel:String;
	[Inspectable(name="Button width",defaultValue=50,type:Number)]
	public var canvasWidth:Number;
	[Inspectable(name="Button height",defaultValue=24,type:Number)]	
	public var canvasHeight:Number;
	
	public var canvasCurveRadius:Number = 2;	
	private var broadcasterObj:Object = null;
	private var label:TextField = null;
	
	function SubmitButtonClass(){
		this.useHandCursor = false;
		this.onRelease = this.onMouseOutEvent;
		this.onReleaseOutside = this.onMouseOutEvent;
		this.onRollOut = this.onMouseOutEvent;
		this.onRollOver = this.onMouseOverEvent;
		this.onPress = this.onMouseDownEvent;
		this.onMouseOutEvent();
		this.createLabel(this.buttonLabel);
	}
	
	private function onMouseOutEvent():Void{
		//logic
	
		//gui
		this.clear();
		var fillType:String = "linear"
		var colors:Array = [0xFFFFFF, 0xBCD0E8];
		var alphas:Array = [100, 100];
		var ratios:Array = [0x00, 0xFF];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(this.canvasWidth, this.canvasHeight, 0.5*Math.PI, 0, -2);
		var spreadMethod:String = "pad";
		
		this.lineStyle(0, 0xA4B8D0, 100, true, "none", "round", "miter", 1);		
		this.beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod); 
		
		this.drawCanvas();
		this.endFill();
		
	}
	
	private function onMouseOverEvent():Void{
		//gui		
		this.clear();
		var fillType:String = "linear"
		var colors:Array = [0xFFFFFF, 0xBCD0E8];
		var alphas:Array = [100, 100];
		var ratios:Array = [0x00, 0xFF];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(this.canvasWidth, this.canvasHeight, 0.5*Math.PI, 0, 2);
		var spreadMethod:String = "pad";
		
		this.lineStyle(0, 0x52667E, 100, true, "none", "round", "miter", 1);		
		this.beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod); 
		
		this.drawCanvas();
		
		this.endFill();

	}
	private function onMouseDownEvent():Void{
		//logic

		//gui
		this.clear();
		var fillType:String = "linear"
		var colors:Array = [0xBCD0E8,0xFFFFFF];
		var alphas:Array = [100, 100];
		var ratios:Array = [0x00, 0xFF];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(this.canvasWidth, this.canvasHeight, 0.5*Math.PI, 0, -2);
		var spreadMethod:String = "pad";
		
		this.lineStyle(0, 0x52667E, 100, true, "none", "round", "miter", 1);		
		this.beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod); 
		
		this.drawCanvas();

		this.endFill();
	}	
	
	private function drawCanvas():Void{
		this.moveTo(this.canvasCurveRadius, 0);
		this.lineTo(this.canvasWidth-this.canvasCurveRadius, 0);
		this.curveTo(this.canvasWidth, 0, this.canvasWidth, this.canvasCurveRadius);
		this.lineTo(this.canvasWidth, this.canvasHeight-this.canvasCurveRadius);
		this.curveTo(this.canvasWidth, this.canvasHeight, this.canvasWidth-this.canvasCurveRadius, this.canvasHeight);
		this.lineTo(this.canvasCurveRadius, this.canvasHeight);
		this.curveTo(0, this.canvasHeight, 0, this.canvasHeight-this.canvasCurveRadius);
		this.lineTo(0, this.canvasCurveRadius);
		this.curveTo(0, 0, this.canvasCurveRadius, 0);
	}
	
	private function createLabel(label:String):Void{
		this.label = this.createTextField("label",this.getNextHighestDepth(),0,0,this._width,this._height);
		var labelFormat:TextFormat = new TextFormat();
		labelFormat.font = "Verdana";
		labelFormat.size = 10;
		labelFormat.bold = true;
		this.label.type = "dynamic";
		this.label.autoSize = true;
		this.label.selectable = false;
		this.label.setNewTextFormat(labelFormat);
		this.label.text = label;
		this.label._x = (this._width - this.label._width)/2;		
		this.label._y = (this._height - this.label._height)/2;
//		trace(this.label._height);
	}
}